/*
 * Created on Jan 28, 2006
 */
package util;

/**
 * @author Valter Camargo
 *
 */

import java.util.*;

public class FrameworkTime extends GregorianCalendar {
	
	private int hour;
	private int minute;
	private int second;
	
	public FrameworkTime(){
		
		GregorianCalendar currentDate = new GregorianCalendar();
		this.hour = currentDate.get(GregorianCalendar.HOUR);
		this.minute = currentDate.get(GregorianCalendar.MINUTE);
		this.second = currentDate.get(GregorianCalendar.SECOND);
	}
	
	public FrameworkTime(GregorianCalendar date){
		
		this.hour   = date.get(GregorianCalendar.HOUR);
		this.minute = date.get(GregorianCalendar.MINUTE);
		this.second = date.get(GregorianCalendar.SECOND);
		
	}
	
	public FrameworkTime(int hour, int minute, int second){
		this.hour = hour;
		this.minute = minute;
		this.second = second;
	}
	
	public int getHour(){
		return this.hour;
	}
	public int getMinute(){
		return this.minute;
	}
	public int getSecond(){
		return this.second;
	}
	
	public void setHour(int hour){
		this.hour = hour;
	}
	public void setMinute(int minute){
		this.minute = minute;
	}
	public void setSecond(int second){
		this.second = second;
	}
	
	public String getStringTimeHMS(){
		
		return this.hour + ":" + this.minute + ":" + this.second;
		
	}
	
	public void convertStringTimeIntoFrameworkTime(String time)
	{
	 try
	 {

		if (time.indexOf(":") != -1){
			
			String hourString = time.substring(0,time.indexOf(":"));
			if (hourString.length() == 2){
				int hour = new Integer(hourString).intValue();
				if (hour < 0 && hour > 24)	{
					
					throw new InvalidHourException();
				}
				else{
					
					this.hour = hour;
					int minute = new Integer(time.substring(time.indexOf(":")+1, time.lastIndexOf(":"))).intValue();
					
					if (minute >= 0 && minute <= 60){
						
						this.minute = new Integer(minute).intValue();
						int second = new Integer(time.substring(time.lastIndexOf(":")+1,time.length())).intValue();
						if (second >= 0 && second <= 60 ){
							this.second = new Integer(second).intValue();
							
						}
						else{
							
							throw new InvalidSecondException();
							
						}	
					}
					else{
						
						throw new InvalidMinuteException();
					}
				}
				
			}else{
				
				throw new InvalidHourException();
				
			}

		}
		else{
			throw new WrongTimeFormatException(time);
		}
	
	}
	catch(InvalidHourException e){
		
		System.out.println("CATCH: FrameworkDate (String): convertStringDateIntoFrameworkDate " + e.getMessage());
		
	}
	catch(InvalidMinuteException e){
		
		System.out.println("CATCH: FrameworkDate(String): convertStringDateIntoFrameworkDate" + e.getMessage());
	}
	catch(InvalidSecondException e){
		
		System.out.println("CATCH: FrameworkDate(String): convertStringDateIntoFrameworkDate" + e.getMessage());
		
	}
	catch(WrongTimeFormatException e){
		
		System.out.println("CATCH: FrameworkDate(String): convertStringDateIntoFrameworkDate" + e.getMessage());
		
	}
	
  }

	
/*	public static int getIntervalOfMinutesFromThisTimeUpNow(FrameworkDate time) throws DifferentYearsException, 
	DifferentMonthException, DifferentDaysException, DifferentHoursException{
		
		FrameworkTime currentDate = new FrameworkTime();
		
		if (time.getYear() != currentDate.getYear()){
			
			throw new DifferentYearsException();
			
		}else{
			
			if (time.getMonth() != currentDate.getMonth()){
				
				throw new DifferentMonthException();
			}
			else{
				if (time.getDay() != currentDate.getDay()){
					
					throw new DifferentDaysException();
					
				}
				else{
		
					if (time.getHour() != currentDate.getHour()){
						
						throw new DifferentHoursException();
					}
					else{
					
						int intervalOfMinutes = currentDate.getMinute() - time.getMinute();
						return intervalOfMinutes;
						
					}
				}
			}
		}
	}
*/

	
}
